/*
 * @Descripttion: 
 * @version: 
 * @Author: yuanliutech
 * @Date: 2025-03-12 17:09:03
 * @LastEditors: yuanliutech@lwj
 * @LastEditTime: 2025-03-19 18:36:32
 */

const app = getApp()
import {
  showMsg
} from '../../../../../utils/config.js'
import {
  reqConsumerRoomList
} from '../../../../../request/api.js'
Component({
  properties: {
    show: false,
  },
  options: {
    // addGlobalClass: true
  },

  data: {
    dataList: [],
    roomItemInfo: {},
  },

  observers: {

    show(val) {
      if (!val) return
      if (!(this.data.dataList && this.data.dataList.length)) {
        this.getDataList()
      }
    }
  },
  async attached() {


  },
  detached() {},


  methods: {
    // 获取列表
    async getDataList() {
      let params = {
        // homeId: '1906590101087543298',
        homeId: app.globalData.familyInfo.id,
      }
      const res = await reqConsumerRoomList(params)
      if (res.code !== 20000) return showMsg(res.message)
      let {
        rows
      } = res.data
      this.setData({
        dataList: rows || []
      })
    },

    itemClick(e) {
      let type = e.type
      let id = ''
      if (type == 'change') {
        id == e.detail
      } else {
        id = e.target.dataset.id
      }
      let {
        dataList
      } = this.data
      let roomItemInfo = {}
      dataList.forEach(item => {
        if (item.id === id) {
          roomItemInfo = item
        }
      })
      this.setData({
        roomItemInfo
      })
    },

    itemClick1(e) {
      let {
        item
      } = e.currentTarget.dataset
      this.setData({
        roomItemInfo: item,
      })
    },

    confirm() {
      this.triggerEvent('confirmRoomSelection', {
        action: 'confirm',
        roomInfo: this.data.roomItemInfo
      });
    },

    onClose() {
      this.triggerEvent('confirmRoomSelection', {
        action: 'cancel',
      });
    },

  }
})